﻿Type=Activity
Version=3.15
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	Dim V_RYBM As String
	Dim V_RYMC As String
	
	Dim FRYBM As String
	Dim FRYData As List

End Sub

Sub Globals

	Dim HttpJobTool As HttpJob
	
	Dim lsvKS As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
	Activity.LoadLayout("FormLoginKS")
	Activity.Title = "选择登陆科室"
	
End Sub

Sub Activity_Resume
	If FRYBM <> V_RYBM Then
		RefreshData
	Else
		InitLoginKS(FRYData)
	End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub RefreshData
	Dim sURL,sUser,sSession,sText As String
	
	sUser = PublicVar.GV_DesTool.Base64encrypt(PublicVar.GV_UserCode)
	sSession = PublicVar.GV_DesTool.Base64encrypt(PublicVar.GV_UserSession)
	
	sText = "User=" & sUser & "&Session=" & sSession
	 
	sURL = PublicVar.GetServerUrl&"/getloginks"
	HttpJobTool.Initialize("Job1",Me)
	HttpJobTool.PostString(sURL,sText)
	
	ProgressDialogShow("正在获取数据，请稍候...")		
	
End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      If Job.JobName = "Job1" Then
				HttpJobSuccess(Job)
      End If
   Else
		HttpJobError(Job)
   End If
   Job.Release
End Sub

Sub HttpJobSuccess (Job As HttpJob)   
	Dim sResult,sCode,sData As String
	Dim mapResult As Map
	
	ProgressDialogHide
	sResult = Job.GetString.Trim
	
	PublicVar.GV_JSonTool.Initialize(sResult)
	mapResult = PublicVar.GV_JSonTool.NextObject
	
	sCode = mapResult.Get("Code")
	If sCode<>"0" Then
		sResult = mapResult.Get("Message")
		ToastMessageShow("获取数据失败"&CRLF &sResult, True)
		
		'
		PublicVar.CheckSession(sCode)
		
		Return
	End If
	
	sData = mapResult.Get("Data")
	If sData ="" Then
		ToastMessageShow("获取数据失败"&CRLF &"返回的数据为空", True)	
		Return	
	
	End If
	
	sData = PublicVar.GV_DesTool.Base64decrypt(sData)
	PublicVar.GV_JSonTool.Initialize(sData)
	FRYData = PublicVar.GV_JSonTool.NextArray
	FRYBM = V_RYBM
	InitLoginKS(FRYData)

End Sub

Sub HttpJobError (Job As HttpJob) 
	Dim sMsg As String
	ProgressDialogHide
	
	Log("Error: " & Job.ErrorMessage)
	sMsg = "获取登陆科室数据失败."& CRLF & Job.ErrorMessage 
  ToastMessageShow(sMsg, True)
End Sub

Sub InitLoginKS(lsRecords As List)
	Dim sKSBM,sKSMC As String
	Dim mapResult As Map
	
	lsvKS.Clear
	For i = 0 To lsRecords.Size - 1 
		mapResult = lsRecords.Get(i)
		
		sKSBM = mapResult.Get("KSBM")
		sKSMC = mapResult.Get("KSMC")
		
		lsvKS.AddSingleLine2(sKSBM & " " &sKSMC,mapResult)	

	Next

End Sub

Sub lsvKS_ItemClick (Position As Int, Value As Object)
	Dim sMsg As String
	Dim mapResult As Map
	ProgressDialogHide
	mapResult = Value
	
	sMsg = "已选择"&mapResult.Get("KSBM") & " " & mapResult.Get("KSMC")
	ToastMessageShow (sMsg, True)
	'StartActivity("MainXT")  '主菜单界面
	
	PublicVar.GV_Login_KSBM = mapResult.Get("KSBM")
	
	BHList.V_KSBM = mapResult.Get("KSBM")
	BHList.V_KSMC = mapResult.Get("KSMC")
	BHList.V_YSBM = V_RYBM
	BHList.V_YSMC = V_RYMC
	BHList.V_CXLX = 0
	StartActivity("BHList")  '病人列表
End Sub